package com.linkhub.oms.admin.modules.stock.domain.dto;

import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.linkhub.oms.common.util.WmsUtil;
import com.linkhub.oms.data.sync.api.wms.domain.dto.WmsEntryOrderBatchCreateDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName CreateInboundDTO
 * @Description TODO
 * @Author XieYu
 * @Date 2024/7/3 22:39
 * @Version 1.0
 */
@Data
public class CreateInboundDTO implements Serializable {
    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "本地商品skuId")
    private String skuId;

    @ApiModelProperty(value = "供应商id")
    private Long supplierId;

    @ApiModelProperty(value = "仓库")
    private String stashName;

    @ApiModelProperty(value = "业务类型")
    private String businessType;

    @ApiModelProperty(value = "业务标识")
    private String businessNo;

    @ApiModelProperty(value = "数量")
    private Integer skuQuantity;

    public static List<CreateInboundDTO> convert(WmsEntryOrderBatchCreateDTO wmsEntryOrderBatchCreateDTO) {
        List<CreateInboundDTO> result = Lists.newArrayList();
        if (Objects.nonNull(wmsEntryOrderBatchCreateDTO) && CollUtil.isNotEmpty(wmsEntryOrderBatchCreateDTO.getProductInfo())) {
            wmsEntryOrderBatchCreateDTO.getProductInfo().forEach(product -> {
                CreateInboundDTO createInboundDTO = new CreateInboundDTO();
                createInboundDTO.setUserId(WmsUtil.getUserId(product.getItemCode()));
                createInboundDTO.setSkuId(WmsUtil.getSkuId(product.getItemCode()));
                createInboundDTO.setSupplierId(Long.parseLong(wmsEntryOrderBatchCreateDTO.getSupplierCode()));
                createInboundDTO.setStashName(wmsEntryOrderBatchCreateDTO.getWarehouseCode());
                createInboundDTO.setBusinessType(wmsEntryOrderBatchCreateDTO.getOrderType());
                createInboundDTO.setBusinessNo(wmsEntryOrderBatchCreateDTO.getEntryOrderCode());
                createInboundDTO.setSkuQuantity(Integer.parseInt(product.getPlanQty()));
                result.add(createInboundDTO);
            });
        }
        return result;
    }
}
